import React, { Component } from 'react'
import qs from 'qs'
import { getGoods } from '../request/cate_request';


export default class GoodsList extends Component {
    state = {
        type_name: '',
        getGoods_list: []

    }
    componentWillMount() {
        let { type_id, type_name } = qs.parse(this.props.location.search.substring(1));
        this.setState({ type_name })
        getGoods(type_id).then(res => {
            this.setState({ getGoods_list: res.list })
        })

    }
    render() {
        let { type_name, getGoods_list } = this.state
        return (
            <div>
                <div className="page-title">{type_name}</div>
                {/* <!-- 商品列表 --> */}
                <div className="goodslist">
                    {
                        getGoods_list.map(item => (
                            <div className="item" key={item.id}>
                                <img src={this.$static_host + item.img} onClick={()=>this.props.history.push('/goodsdetail/'+item.id+'/')} />
                                <div>
                                    <h5 onClick={()=>this.props.history.push('/goodsdetail/'+item.id+'/')}>{item.goodsname}</h5>
                                    <p className="price">&yen;{item.price}</p>
                                    <p className="market-price">&yen;{item.market_price}</p>
                                    <button className="btn-cart">加入购物车</button>
                                </div>
                            </div>
                        ))
                    }

                </div>
            </div>
        )
    }
}
